package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.db.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @program: tanhua
 * @description:
 * @author: MR.peng
 * @create: 2022-03-07 12:29
 **/

@DubboService
public class UserApiImpl implements UserApi{



    @Autowired
    private UserMapper userMapper;

    /*
    * 根据手机号码查询手机用户
    * */
    @Override
    public User findByMobile(String mobile) {

        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile",mobile);
        User user = userMapper.selectOne(wrapper);
        return user;
    }
    /*
     * */
    @Override
    public Long save(User user) {
        userMapper.insert(user);//mybatis-plus ：保存成功之后，会自动向user对象中设置id
        return user.getId();
    }


    /*
    * 更新用户
    * */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    /*
    * 查询所有用户*/
    @Override
    public List<User> findAll() {
        return userMapper.selectList(null);
    }


}
